package javaCodeGenerator;

import javaMetaModel.Attribute;
import javaMetaModel.MetaClasse;
import javaMetaModel.MetaInterface;
import javaMetaModel.MetaModel;
import javaMetaModel.MetaPackage;
import javaMetaModel.Methode;
import javaMetaModel.Parameter;
import javaMetaModel.type.MetaDouble;
import javaMetaModel.type.MetaInteger;

public class JavaGeneratorTester {

	public static void main3(String[] args) {
		MetaModel dummyModel = new MetaModel();

		MetaClasse c1 = new MetaClasse("Dummy1");
		MetaClasse c2 = new MetaClasse("Dummy2");
		MetaClasse c3 = new MetaClasse("Dummy3");
		MetaClasse c4 = new MetaClasse("Dummy4");

		c1.setPackage("p1");
		c2.setPackage("p1.p2");

		MetaPackage p1 = new MetaPackage("p1");
		MetaPackage p2 = new MetaPackage("p2");
		p2.setParentPackage(p1);

		c3.setPackage(p2);

		dummyModel.add(c1);
		dummyModel.add(c2);
		dummyModel.add(c3);
		dummyModel.add(c4);

		JavaCodeGenerator generator = new JavaCodeGenerator();
		dummyModel.accept(generator);
	}

	public static void main(String[] args) {
		MetaModel dotMetaModel = new MetaModel();

		MetaClasse graphvizClass = new MetaClasse("GraphvizModel");
		graphvizClass.setPackage("dotMetaModel");

		MetaClasse graphClass = new MetaClasse("Graph");
		graphClass.setPackage("dotMetaModel");

		graphvizClass.addAttribute(graphClass, "graphs");

		MetaClasse stmtClass = new MetaClasse("Statement");
		stmtClass.setPackage("dotMetaModel.statement");

		graphClass.addAttribute(stmtClass, "stmts");

		MetaClasse portClass = new MetaClasse("Port");
		portClass.setPackage("dotMetaModel");

		MetaClasse aListClass = new MetaClasse("AList");
		aListClass.setPackage("dotMetaModel");

		MetaClasse attrListClass = new MetaClasse("AttributeList");
		attrListClass.setPackage("dotMetaModel.statement");
		attrListClass.setExtends(stmtClass);
		attrListClass.addAttribute(aListClass, "aList", "-1");

		MetaClasse nodeStmtClass = new MetaClasse("NodeStatement");
		nodeStmtClass.setPackage("dotMetaModel.statement");
		nodeStmtClass.setExtends(stmtClass);
		nodeStmtClass.addAttribute(portClass, "port");
		nodeStmtClass.addAttribute(attrListClass, "attributes");

		MetaClasse nodeIdClass = new MetaClasse("NodeId");
		nodeIdClass.setPackage("dotMetaModel");
		nodeIdClass.addAttribute(portClass, "port");

		MetaClasse edgeRHSClass = new MetaClasse("EdgeRHS");
		edgeRHSClass.setPackage("dotMetaModel");

		MetaClasse edgeStmtNodeClass = new MetaClasse("EdgeStatementNode");
		edgeStmtNodeClass.setPackage("dotMetaModel.statement");
		edgeStmtNodeClass.setExtends(stmtClass);
		edgeStmtNodeClass.addAttribute(nodeIdClass, "nodeId");
		edgeStmtNodeClass.addAttribute(attrListClass, "attributes");
		edgeStmtNodeClass.addAttribute(edgeRHSClass, "edgeRHS");

		MetaClasse attributeClass = new MetaClasse("Attribute");
		attributeClass.setPackage("dotMetaModel.statement");
		attributeClass.setExtends(stmtClass);

		MetaClasse attrStmtClass = new MetaClasse("AttributeStatement");
		attrStmtClass.setPackage("dotMetaModel.statement");
		attrStmtClass.setExtends(stmtClass);
		attrStmtClass.addAttribute(attrListClass, "attributes");

		MetaClasse subgraphClass = new MetaClasse("Subgraph");
		subgraphClass.setPackage("dotMetaModel.statement");
		subgraphClass.setExtends(stmtClass);
		subgraphClass.addAttribute(stmtClass, "stmts");

		MetaClasse edgeStmtSubgraphClass = new MetaClasse(
				"EdgeStatementSubgraph");
		edgeStmtSubgraphClass.setPackage("dotMetaModel.statement");
		edgeStmtSubgraphClass.setExtends(stmtClass);
		edgeStmtSubgraphClass.addAttribute(attrListClass, "attributes");
		edgeStmtSubgraphClass.addAttribute(edgeRHSClass, "edgeRHS");
		edgeStmtSubgraphClass.addAttribute(subgraphClass, "subgraph");

		MetaClasse edgeRHSNodeClass = new MetaClasse("EdgeRHSNode");
		edgeRHSNodeClass.setPackage("dotMetaModel");
		edgeRHSNodeClass.setExtends(edgeRHSClass);
		edgeRHSNodeClass.addAttribute(nodeIdClass, "nodeId");

		MetaClasse edgeRHSSubgraphClass = new MetaClasse("EdgeRHSSubgraph");
		edgeRHSSubgraphClass.setPackage("dotMetaModel.statement");
		edgeRHSSubgraphClass.setExtends(edgeRHSClass);
		edgeRHSSubgraphClass.addAttribute(subgraphClass, "subgraph");

		dotMetaModel.add(graphvizClass);
		dotMetaModel.add(graphClass);
		dotMetaModel.add(stmtClass);
		dotMetaModel.add(nodeStmtClass);
		dotMetaModel.add(edgeStmtNodeClass);
		dotMetaModel.add(edgeStmtSubgraphClass);
		dotMetaModel.add(attributeClass);
		dotMetaModel.add(attrStmtClass);
		dotMetaModel.add(attrListClass);
		dotMetaModel.add(edgeRHSClass);
		dotMetaModel.add(aListClass);
		dotMetaModel.add(edgeRHSNodeClass);
		dotMetaModel.add(edgeRHSSubgraphClass);
		dotMetaModel.add(nodeIdClass);
		dotMetaModel.add(subgraphClass);
		dotMetaModel.add(portClass);

		JavaCodeGenerator generator = new JavaCodeGenerator();
		dotMetaModel.accept(generator);
	}

	public static void main2(String[] args) {
		MetaModel metaModel = new MetaModel();

		MetaClasse firstClass = new MetaClasse("firstClass");
		firstClass.setPackage("firstPackage");
		MetaClasse secondClass = new MetaClasse("secondClass");
		MetaInterface firstInterface = new MetaInterface("firstInterface");

		firstClass.addImplements(firstInterface);
		secondClass.setExtends(firstClass);

		Methode firstMethod = new Methode("firstMethod");
		firstMethod.addParam(new Parameter(new MetaInteger(), "firstParam"));
		firstMethod.addParam(new Parameter(new MetaDouble(), "secondParam"));

		Methode secondMethode = new Methode("secondMethod");

		firstInterface.addMethod(firstMethod);

		firstClass.addMethod(firstMethod);
		secondClass.addMethod(secondMethode);

		Parameter firstParam = new Parameter(new MetaInteger(), "firstParam");
		firstParam.setFinal(true);

		Methode thirdMethod = new Methode("thirdMethod");
		thirdMethod.setReturnType(new MetaDouble());
		thirdMethod.addParam(firstParam);
		thirdMethod.setPublic();
		thirdMethod.setStatic(true);

		thirdMethod.getBody().addContent("Integer i = 1;");

		secondClass.addMethod(thirdMethod);

		MetaClasse thirdClass = new MetaClasse("thirdClass");
		thirdClass.setPublic();
		thirdClass.addComment("Troisième classe!");
		thirdClass.addComment("Classe Test comm and @");

		thirdClass.addAnnotation("SuppressWarnings");

		MetaClasse fourthClass = new MetaClasse("fourthClass");
		fourthClass.setAbstract(true);

		Methode fourthMethod = new Methode("fourthMethod");
		fourthMethod.setPublic();
		fourthMethod.setStatic(true);
		fourthMethod.setAbstract(true);
		fourthMethod.addComment("Commentaire de méthode");
		fourthMethod.addAnnotation("SuppressWarnings");

		Parameter param = new Parameter(new MetaInteger(), "anInteger");
		param.addComment("Entier passé en param dude!");
		fourthMethod.addParam(param);
		fourthClass.addMethod(fourthMethod);

		Attribute firstAttr = new Attribute(new MetaDouble(), "mDoubleAttr",
				"0.5");
		firstAttr.addComment("Valeur double de test pour la classe!");
		fourthClass.addAttribute(firstAttr);

		metaModel.add(firstInterface);
		metaModel.add(firstClass);
		metaModel.add(secondClass);
		metaModel.add(thirdClass);
		metaModel.add(fourthClass);

		JavaCodeGenerator generator = new JavaCodeGenerator();

		metaModel.accept(generator);

	}
}
